import type { RouteObject } from 'react-router-dom'
import { componentMap } from '../router/routerMap'
import type { MenuItem } from '../type/menu.ts'

export const generateRoute = (menuList: Array<MenuItem>): Array<RouteObject> => {
  return menuList.map((item: MenuItem) => {
    const object: RouteObject = {
      path: item.key,
      element: item.children ? null : componentMap[item.key],
    }
    if (item.children) {
      object.children = generateRoute(item.children)
    }
    return object
  })
}
